using UnityEngine;
using System.Collections;
using System;
using System.Runtime.InteropServices;    

public class btBoxCollider : btRigidBody {
	
	public Vector3 Extent = Vector3.one;
	public float mass = 1.0f;
	public float restitution = 0;
	public float linearDamping = 0;
	public float angularDamping = 0;
	public float friction = 0;
	public float linearThreshold = 0;
	public float angularThreshold = 0;
	
	
	private uint id, colliderId;
	private float pX, pY, pZ;
	private float rX, rY, rZ, rW;
	
	[DllImport ("__Internal")] private static extern uint createBoxShape(float halfExtentX, float halfExtentY, float halfExtentZ, out uint colliderId);
	//[DllImport ("__Internal")] private static extern void createRigidBody(float X, float Y, float Z, float rX, float rY, float rZ, float rW, float mass, out uint id, uint colliderId);
	//[DllImport ("__Internal")] private static extern void getPosition(out float X, out float Y, out float Z, uint id);
	//[DllImport ("__Internal")] private static extern void getRotation(out float rX, out float rY, out float rZ, out float rW, uint id);
		
	void Start () 
	{
		createBoxShape(Extent.x/2.0f, Extent.y/2.0f, Extent.z/2.0f, out colliderId);
		createRigidBody(transform.position.x, transform.position.y, transform.position.z, 
						transform.rotation.x, transform.rotation.y, transform.rotation.z, transform.rotation.w, 
						mass, 
						restitution,
						linearDamping, angularDamping, 
						friction, 
						linearThreshold, angularThreshold,out 
						id, colliderId);
	}	
	
	void Update () 
	{
		//TransormUpdate();
		getOrigin(out pX, out pY, out pZ, id);
		transform.position = new Vector3(pX,pY,pZ);
		getRotation(out rX, out rY, out rZ, out rW, id);
		transform.rotation = new Quaternion(rX,rY,rZ,rW);
	}
}